const fs = require('fs-extra')
const R = require('ramda')
const {booksFile} = require('./config')

const print = R.forEach(b => console.log(`${b.price} ${b.title}`))

const highest = R.pipe(
  R.sort((a, b) => b.price - a.price),
  R.take(50),
  print
)

const lowest = R.pipe(
  R.sort((a, b) => a.price - b.price),
  R.take(100),
  print
)

const list = async () => {
  const booksInFile = await fs.readJson(booksFile)
  highest(booksInFile)
}

module.exports = list
